/**
 * Created with JetBrains WebStorm.
 * User: gcw
 * Date: 14-1-10
 * Time: 下午12:59
 * To change this template use File | Settings | File Templates.
 */
// 加载模块
//加载 在node——modules的express模块

var express = require('express');
var http = require('http');
var path = require('path');
var io = require('socket.io');
var router = require('./lib/router');
var socket = require('./lib/ws/socketTemp');


//初始化 express
var app = express();

//设置监听端口
app.set('port',process.env.PORT || 3000);

// 设置 express寻找（客户端的）资源位置，静态的网页、css、js等
app.use(express.static(__dirname + '/frontend'));

//设置 ejsfile 引擎，这里是通过express 去帮助我们加载
app.set('view engine', 'ejs');

//设置ejs 文件存放位置
app.set('views',__dirname+'/frontend/ejsfile');

//设置网站图标
app.use(express.favicon());

//设置日志
app.use(express.logger('dev'));
// 设置 cookie
app.use(express.cookieParser());

//核心内部加载的方法
/*
*   app.use(express.bodyParser());
*  app.use(express.methodOverride());
*  app.use(app.router);
*  app.use(express.static(path.join(__dirname, 'frontend')));
* */
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'frontend/html')));

//错误控制台输出
if('development' == app.get('env')){
    app.use(express.errorHandler());
}

var server = http.createServer(app).listen(app.get('port'),function(){
        console.log('Express port' + app.get('port'));
});

//监听socket

// 创建一个Socket.IO实例，把它传递给服务器
var io_obj = io.listen(server);
io_obj.on('connection', function(socket_obj){
    socket.createCon(socket_obj);
});

//-------------------路由开始--------------------------------------------------
router.routeFun(app);






